package fivestar.ui.user;
import java.awt.Font;
import java.awt.Frame;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRootPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;

import org.netbeans.validation.api.ValidatorUtils;
import org.netbeans.validation.api.builtin.stringvalidation.StringValidators;
import org.netbeans.validation.api.ui.ValidationGroup;
import org.netbeans.validation.api.ui.swing.ValidationPanel;
 
public class Login extends javax.swing.JDialog {
	
	private static final long serialVersionUID = -1411049000862788016L;
	
	private JPanel pnlLoginUser;
	private JPanel pnlLogin;
	private JPanel pnlImagesLogin;
	private JPasswordField txtPassword;
	private JButton btnAccept;
	private JButton btnCancel;
	private JLabel lblTitleLogin;
	private JTextField txtUser;
	private JLabel lblPassword;
	private JLabel lblUser;
	
	ValidationPanel pnlValidation;
	ValidationGroup group;
 
	public Login(Frame parent, boolean modal){
		super(parent, modal);
		initComponents();
		this.setLocationRelativeTo(null);
        JRootPane root = this.getRootPane();
        root.setDefaultButton(btnAccept);
	} 
	
	@SuppressWarnings("unchecked")
	private void initComponents() {
		try {
			
			java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("fivestar/ui/main/Bundle");
			
			getContentPane().setLayout(null);    

			pnlLoginUser = new JPanel();
			pnlLoginUser.setBounds(0, 0, 512, 202);
			getContentPane().add(pnlLoginUser);
	        pnlLoginUser.setLayout(null);
			
	        pnlValidation = new ValidationPanel();
			pnlValidation.setBounds(0, 0, 512, 245);
			pnlValidation.setInnerComponent(pnlLoginUser);
			getContentPane().add(pnlValidation);
			group = pnlValidation.getValidationGroup();
			
	        pnlImagesLogin = new JPanel();
	        pnlImagesLogin.setBounds(10, 35, 129, 122);
	        pnlImagesLogin.setBorder(BorderFactory.createTitledBorder(null,
                    "", TitledBorder.DEFAULT_JUSTIFICATION,
                    TitledBorder.DEFAULT_POSITION,
                    new Font("Comic Sans MS", 0, 10)));
	        pnlLoginUser.add(pnlImagesLogin);
 
			lblTitleLogin = new JLabel();
			lblTitleLogin.setHorizontalAlignment(SwingConstants.CENTER);
			lblTitleLogin.setFont(new Font("Tahoma", Font.BOLD, 18));
			pnlLoginUser.add(lblTitleLogin);
			lblTitleLogin.setText(bundle.getString("Login.lblTitleLogin.text"));
			lblTitleLogin.setBounds(149, 11, 267, 22);
 
			pnlLogin = new JPanel();
			pnlLogin.setLayout(null);
			pnlLogin.setBounds(154, 51, 341, 93); 
			pnlLogin.setBorder(BorderFactory.createTitledBorder(null,
                    "", TitledBorder.DEFAULT_JUSTIFICATION,
                    TitledBorder.DEFAULT_POSITION,
                    new Font("Comic Sans MS", 0, 10)));
			pnlLoginUser.add(pnlLogin);
			
			
			lblUser = new JLabel();
			lblUser.setFont(new Font("Tahoma", Font.BOLD, 14));
			pnlLogin.add(lblUser);
			lblUser.setText(bundle.getString("Login.lblUser.text"));
			lblUser.setBounds(20, 20, 94, 16);
			
			txtUser = new JTextField();
			txtUser.setFont(new Font("Tahoma", Font.BOLD, 14));
			txtUser.setName("User");
			txtUser.setBounds(124, 20, 206, 23);
			pnlLogin.add(txtUser);

			lblPassword = new JLabel();
			lblPassword.setFont(new Font("Tahoma", Font.BOLD, 14));
			lblPassword.setBounds(20, 56, 94, 16);
			pnlLogin.add(lblPassword);
			lblPassword.setText(bundle.getString("Login.lblPassword.text"));

			txtPassword = new JPasswordField();
			txtPassword.setName("Password");
			pnlLogin.add(txtPassword);
			txtPassword.setBounds(124, 56, 206, 23);
			
			btnAccept = new JButton();
			btnAccept.setFont(new Font("Tahoma", Font.BOLD, 11));
			btnAccept.setIcon(new ImageIcon(Login.class.getResource("/fivestar/ui/main/images/Aceptar.png")));
			pnlLoginUser.add(btnAccept);
			btnAccept.setText(bundle.getString("Login.btnAccept.text"));
			btnAccept.setBounds(149, 155, 120, 33);

			btnCancel = new JButton();
			btnCancel.setFont(new Font("Tahoma", Font.BOLD, 11));
			btnCancel.setIcon(new ImageIcon(Login.class.getResource("/fivestar/ui/main/images/Cancelar.png")));
			pnlLoginUser.add(btnCancel);
			btnCancel.setText(bundle.getString("Login.btnCancel.text"));
			btnCancel.setBounds(270, 155, 120, 33);
 
			group.add(txtPassword, ValidatorUtils
					.merge(StringValidators.REQUIRE_NON_EMPTY_STRING));
			group.add(txtUser, ValidatorUtils
					.merge(StringValidators.REQUIRE_NON_EMPTY_STRING));

			this.setSize(528, 285);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
            	Login dialog = new Login(null,true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
}
